package com.tuozixuan.thymeleaf.demo;


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

import com.tuozixuan.thymeleaf.demo.model.Person;

public class ThymeleafDemo {

	public static void main(String[] args) {
		
		ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
		templateResolver.setTemplateMode(TemplateMode.HTML);
		templateResolver.setPrefix("/template/");
		templateResolver.setSuffix(".html");
		
		TemplateEngine templateEngine = new TemplateEngine();
		templateEngine.setTemplateResolver(templateResolver);
		
		Context context = new Context();
//		context.setVariable("name", "lisi");
		
		Map<String, Object> map = new HashMap<>();
		map.put("name", "lisi");
		map.put("items", Arrays.asList("one", "two", "three"));
		Person person = new Person();
		person.setName("name1");
		Person person2 = new Person();
		person2.setName("name2");
		map.put("persons", Arrays.asList(person, person2));
		context.setVariables(map);
		
		String result = templateEngine.process("test", context);
		System.out.println(result);
		
	}

}
